﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using HPT.Utilities;
using HPT;
using Microsoft.SharePoint;

namespace News.WebParts.ConfigureWebPart
{
    public partial class ConfigureWebPartUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnCreateList_Click(object sender, EventArgs e)
        {
            #region News
            if (!OWeb.ListExists(Constants.List.News))
                OWeb.CurrentWeb.Lists.Add(Constants.List.News, "", SPListTemplateType.GenericList);
            var listNews = OWeb.GetList(Constants.List.News);
            if (!listNews.Fields.ContainsFieldWithStaticName("Category"))
            {
                listNews.Fields.Add("Category", SPFieldType.Choice, true);
                string[] datas = { "Kinh doanh", "Công nghệ", "Xóm nhiếp ảnh", "Ban phong trào", "Thể thao", "Sáng tác", "Chân dung", "Cười mỉm chi", "Bạn có biết" };
                var field = new SPFieldChoice(listNews.Fields, "Category");
                field.Choices.AddRange(datas);
                field.Update();
            }
            if (!listNews.Fields.ContainsFieldWithStaticName("Contents"))
            {
                listNews.Fields.Add("Contents", SPFieldType.Note, false);
                var field = new SPFieldMultiLineText(listNews.Fields, "Contents");
                field.RichText = true;
                field.RichTextMode = SPRichTextMode.FullHtml;
                field.Update();
            }
            if (!listNews.Fields.ContainsFieldWithStaticName("Publish")) listNews.Fields.Add("Publish", SPFieldType.Boolean, false);
            if (!listNews.Fields.ContainsFieldWithStaticName("Url")) listNews.Fields.Add("Url", SPFieldType.URL, false);
            if (!listNews.Fields.ContainsFieldWithStaticName("DisplayOrder")) listNews.Fields.Add("DisplayOrder", SPFieldType.Integer, false);
            if (!listNews.Fields.ContainsFieldWithStaticName("HitCounter")) listNews.Fields.Add("HitCounter", SPFieldType.Integer, false);
            #endregion
        }
    }
}
